package com.ltu.model.response;

import com.ltu.base.State;
import org.apache.commons.lang3.builder.ToStringBuilder;

//import com.ltu.base.State;

import io.swagger.annotations.ApiModelProperty;

public class CodeResp{
	@ApiModelProperty("成功：200，其他：失败")
	protected Integer code; // 返回代码，对应message
	@ApiModelProperty("信息描述")
	protected String message;// 返回信息描述
	@ApiModelProperty("服务器时间戳")
	protected Long timestamp;
	public CodeResp(){
		super();
	}

	public CodeResp(State state) {
		setCode(state.getCode());
		setMessage(state.getMessage());
		setTimestamp(System.currentTimeMillis());
	}
	public CodeResp(State.stateDict state) {
		setCode(state.getIndex());
		setMessage(state.getValue());
		setTimestamp(System.currentTimeMillis());
	}
	public CodeResp(Integer code, String msg) {
		setCode(code);
		setMessage(msg);
		setTimestamp(System.currentTimeMillis());
	}
	public CodeResp(String code, String msg) {
		setCode(Integer.parseInt(code));
		setMessage(msg);
		setTimestamp(System.currentTimeMillis());
	}

	public String getMessage() {
		return message;
	}

	public void setMessage(String message) {
		this.message = message;
	}

	public Long getTimestamp() {
		return timestamp;
	}

	public void setTimestamp(Long timestamp) {
		this.timestamp = timestamp;
	}

	public Integer getCode() {
		return code;
	}

	public void setCode(Integer code) {
		this.code = code;
	}
	
	public static CodeResp valueOfSuccess() {
		CodeResp response = new CodeResp(State.SUCCESS);
		return response;
	}
	
	public static  CodeResp valueOfSuccess(String message) {
		CodeResp response = new CodeResp(State.CODE_SUCCESS,message);
		return response;
	}
	
	public static CodeResp codeRespInit(Integer code, String message) {
		CodeResp response = new CodeResp(code,message);
		return response;
	}
	
	@Override
	public String toString() {
		return ToStringBuilder.reflectionToString(this);
	}
}
